package com.wbcs.system.component.container.panel;

import java.util.ArrayList;
import java.util.List;

import com.wbcs.config.component.IComponentConfigBean;
import com.wbcs.config.component.container.AbsContainerConfigBean;
import com.wbcs.config.component.container.panel.PanelBean;
import com.wbcs.config.xml.XmlElementBean;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.IComponentType;
import com.wbcs.system.component.container.AbsContainerType;
import com.wbcs.system.tags.component.AbsComponentTag;
import com.wbcs.util.Consts;

public class Panel extends AbsPanelType
{
    public Panel(AbsContainerType parentContainerType,IComponentConfigBean comCfgBean,ReportRequest rrequest)
    {
        super(parentContainerType,comCfgBean,rrequest);
    }

    public void displayOnPage(AbsComponentTag displayTag)
    {
        if(!rrequest.checkPermission(this.containerConfigBean.getId(),null,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            wresponse.println("&nbsp;");
            return;
        }
        wresponse.println(showContainerStartPart());
        wresponse.println(showContainerTableTag());
        if(rrequest.checkPermission(this.containerConfigBean.getId(),Consts.DATA_PART,null,Consts.PERMISSION_TYPE_DISPLAY))
        {
            if(mChildren!=null&&mChildren.size()>0)
            {
                IComponentType childObjTmp=this.mChildren.entrySet().iterator().next().getValue();
                wresponse.println("<tr>");
                showChildObj(childObjTmp,null);
                wresponse.println("</tr>");
            }
        }
        wresponse.println("</table>");
        wresponse.println(showContainerEndPart());
    }

    @Override
	public AbsContainerConfigBean loadConfig(XmlElementBean eleContainer,AbsContainerConfigBean parent,String tagname)
    {
        PanelBean panelbean=(PanelBean)super.loadConfig(eleContainer,parent,tagname);
        if(panelbean.getLstChildrenIDs().size()>1)
        {
            List<String> lstChildrenIds=new ArrayList<String>();
            lstChildrenIds.add(panelbean.getLstChildrenIDs().get(0));
            for(int i=1;i<panelbean.getLstChildrenIDs().size();i++)
            {
                panelbean.getMChildren().remove(panelbean.getLstChildrenIDs().get(i));
            }
            panelbean.setLstChildrenIDs(lstChildrenIds);
        }
        return panelbean;
    }

    @Override
	protected AbsContainerConfigBean createContainerConfigBean(
            AbsContainerConfigBean parentContainer,String tagname)
    {
        return new PanelBean(parentContainer,tagname);
    }

    @Override
	protected String getComponentTypeName()
    {
        return "container.panel";
    }
}
